package cbh.tool.file;

import cbh.tool.exception.AnnotationNotFoundException;
import cbh.tool.mybatis.annotation.MyTable;
import cbh.tool.mybatis.annotation.MybatisPropertits;

import java.lang.reflect.Field;

/**
 * Created by hx-pc on 16-1-30.
 */
public abstract class AbstractDocumentBuilder implements DocumentBuilderInterface {

    private String basePath;

    private MybatisPropertits propertits;

    private MyTable table;

    private Field[] fields;

    private Class c;

    @Override
    public AbstractDocumentBuilder buildParameter(Class c) throws AnnotationNotFoundException {
        this.c = c;
        propertits = (MybatisPropertits) c.getAnnotation(MybatisPropertits.class);
        table = (MyTable) c.getAnnotation(MyTable.class);
        if(propertits == null || table == null){
            throw new AnnotationNotFoundException();
        }
        fields = c.getDeclaredFields();
        String str = c.getCanonicalName();
        basePath = str.substring(0,str.lastIndexOf(".")).replace(".","/");
        return this;
    }

    public MybatisPropertits getPropertits() {
        return propertits;
    }

    public MyTable getTable() {
        return table;
    }

    public Field[] getFields() {
        return fields;
    }

    public Class getC(){return c;}

    public String getBasePath(){return basePath;}
}
